package com.jlnk.androidfmc.presenter;

import android.content.Context;

import com.jlnk.androidfmc.database.ProductDatabaseHelper;
import com.jlnk.androidfmc.entity.Product;
import com.jlnk.androidfmc.view.CategoryView;

import java.util.List;

public class CategoryPresenter {
    private CategoryView view;
    private ProductDatabaseHelper databaseHelper;

    public CategoryPresenter(CategoryView view, Context context) {
        this.view = view;
        this.databaseHelper = new ProductDatabaseHelper(context);
    }

    public void loadProductsByCategory(int categoryId) {
        new Thread(() -> {
            List<Product> productList = databaseHelper.getProductsByCategory(categoryId);
            view.showProducts(productList);
        }).start();
    }
}